<?php

class Comment_Model extends CI_Model {

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Get list comments by nodeID
     * @param <type> $nodeID
     * @param <type> $limit
     * @param <type> $offset
     * @return <type>
     */
    public function getListCommentByNodeID($nodeID, $limit = 10, $offset = 0)
    {
        $query = 'SELECT SQL_CALC_FOUND_ROWS * FROM comments ';
        $query.= 'WHERE node_id = '. $nodeID .' AND status = 1 ';
        $query.= 'ORDER BY cm_id DESC LIMIT '. $offset .', '. $limit;

        $result['data'] = $this->db->query($query)->result_array();

        $query = 'SELECT FOUND_ROWS() AS total';

        $total  = $this->db->query($query)->row_array('total');

        $result['total'] = $total['total'];

        return $result;
    }

    /**
     * Insert new comment
     * @param <type> $params
     * @return <type>
     */
    public function insertComment($params)
    {
        //Insert comments
        $this->db->insert('comments', $params);

        return $this->db->insert_id();
    }

}

?>